
/**
 * 子弹类型
 */
class BulletType {
	public movieClipDataSet: any;
	public texture: egret.Texture;
	public tag: number;

	/**
	 * 构造函数
	 * @param movieClipDataSet {any} MovieClip数据集(json)
	 * @param texture {egret.Texture} 纹理(png)
	 * @param tag {number} 子弹标识
	 */
	public constructor(movieClipDataSet: any, texture: egret.Texture, tag: number) {
		this.movieClipDataSet = movieClipDataSet;
		this.texture = texture;
		this.tag = tag;
	}
}

/**
 * 子弹
 */
class BulletSprite extends egret.Sprite {
	// 动画对象
	private _movieClip: egret.MovieClip;
	// 子弹类型对象
	private _bulletType: BulletType;
	// 炮塔位置
	public _turretPoint: egret.Point;
	// 距离炮塔的位置
	public _turretDistance: number;
	// 炮塔弧度
	public _turretRadian: number;

	/**
	 * 构造函数
	 * @param bulletType BulletType 子弹类型
	 */
	public constructor(bulletType: BulletType) {
		super();
		this._bulletType = bulletType;
		this._turretPoint = new egret.Point();
	};
	/**
	 * 开始动画
	 */
	public startAnimation(): void {
		var mcDataFactory = new egret.MovieClipDataFactory(this._bulletType.movieClipDataSet, this._bulletType.texture);
		this._movieClip = new egret.MovieClip(mcDataFactory.generateMovieClipData());
		this.addChild(this._movieClip);
		this.anchorOffsetX = this.width / 2;
		this.anchorOffsetY = this.height / 2;
		// 循环播放
		this._movieClip.gotoAndPlay(1, -1);
	}
	/**
	 * 停止动画
	 */
	public stopAnimation() {
		this._movieClip.stop();
	}
	/**
	 * 改变动画速度
	 * @param frame number 帧
	 */
	public changeFrameRate(frame: number) {
		this._movieClip.frameRate = frame;
	}
}